import umEventApi from '@questionApi/umEvent'
import {validatenull} from '@/libs/validate'

export const caseMixin = {
  props: {
    statisticsShow: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      // 未结案案件点集
      caseMarkers: []
    }
  },
  methods: {
    /**
     * @Author ling.yuan@topevery.club
     * @Date 2019/12/09 13:28:10
     * @Param event 是否开启案件图层(true/false)
     * @Description 加载案件数据并添加至地图
     */
    initCaseFeature(event, target = 'case') {
      if (event) {
        const query = {
          page: false,
          params: [
            {
              cond: 'and',
              group: [
                {
                  key: 'caseStatus',
                  value: '0',
                  cond: 'or_eq'
                },
                {
                  key: 'caseStatus',
                  value: '2',
                  cond: 'or_eq'
                }
              ]
            }
          ]
        }
        umEventApi.listEventData(query)
          .then(res => {
            // 将案件加载到地图上
            this.caseMarkers = []
            var icon = './image/map/case-biue.png'
            if (res.data.length > 0) {
              res.data.forEach(item => {
                // 坐标有效
                if (!validatenull(item.geoX) && !validatenull(item.geoY)) {
                  if (item.surplusType === '1') {
                      icon = './image/map/case-blue.png'
                  } else if (item.surplusType === '0') {
                      icon = './image/map/case-orange.png'
                  } else if (item.surplusType === '-1') {
                      icon = './image/map/case-red.png'
                  }
                  const obj = {
                    id: item.id,
                    title: item.caseTitle,
                    target: target,
                    coordinates: [item.geoX, item.geoY],
                    animate: true,
                    stopEvent: true,
                    icon: icon,
                    data: item
                  }
                  this.caseMarkers.push(obj)
                }
              })
              this.showMarkerFeature(this.caseMarkers, false, target)
            } else {
              this.$message.warning('暂无未结案案件')
            }
          })
          .catch(() => {

          })
      } else {
        // 清除图层feature
        if (this.caseMarkers.length > 0) {
          this.clearMarkerFeature(target)
          this.$refs.caseBar.handleCloseCaseInfo()
        }
      }
    },
    /**
     * @Author ling.yuan@topevery.club
     * @Date 2019/12/09 14:48:39
     * @Description 案件点击展示详情
     */
    handleCaseClick(event) {
      this.$refs.caseBar.handleShowCaseInfo(event)
      this.$refs.staffBar.handleStaffAllHide()
      this.$refs.videoBar.handleCloseVideoDetail()
      this.$refs.carBar.handleCloseCarDetail()
    },
    /**
     * @Author ling.yuan@topevery.club
     * @Date 2019/12/12 14:20:06
     * @Description 案件定位
     */
    handleCasePosition(item, target = 'case') {
      for (let i = 0; i < this.caseMarkers.length; i++) {
        if (this.caseMarkers[i].id === item.id) {
          this.handleItemSelect(this.caseMarkers[i], false, target, false)
          break
        }
      }
    }
  }
}
